package common;

import java.util.Set;

import net.sf.json.JSONArray;
import utils.StringUtil;

public class Menu {

	public static final String[][][] MENU = new String[10][10][10];

	static {
		MENU[0][0][0] = "个人中心";
		MENU[0][0][1] = "nothing";
		MENU[0][1][0] = "帐号信息";
		MENU[0][1][1] = "subject_show.html";
		MENU[0][2][0] = "商户信息";
		MENU[0][2][1] = "merchant_show.html";
		MENU[0][3][0] = "我的网站";
		MENU[0][3][1] = "website_list.html";
		MENU[0][4][0] = "子账户管理";
		MENU[0][4][1] = "subject_list.html";
		MENU[0][5][0] = "风控设置";
		MENU[0][5][1] = "venture_list.html";
		MENU[0][6][0] = "公告历史";
		MENU[0][6][1] = "news_list.html";

		MENU[1][0][0] = "交易管理";
		MENU[1][0][1] = "nothing";
		MENU[1][1][0] = "交易列表";
		MENU[1][1][1] = "transaction_view.html";
		MENU[1][2][0] = "拦截记录";
		MENU[1][2][1] = "intercept_list.html";
		MENU[1][3][0] = "物流信息上传";
		MENU[1][3][1] = "transaction_listlogic.html";
		MENU[1][4][0] = "退款记录";
		MENU[1][4][1] = "msm_viewrefund.html";
		MENU[1][5][0] = "拒付记录";
		MENU[1][5][1] = "msm_viewrefuse.html";
		MENU[1][6][0] = "冻结记录";
		MENU[1][6][1] = "msm_viewfreeze.html";
		MENU[1][7][0] = "保证金记录";
		MENU[1][7][1] = "msm_viewmortgage.html";

		MENU[2][0][0] = "资金情况";
		MENU[2][0][1] = "nothing";
		MENU[2][1][0] = "资金明细";
		MENU[2][1][1] = "smb_viewfince.html";
		MENU[2][2][0] = "收支明细列表";
		MENU[2][2][1] = "smb_list.html?smbState=1";
		MENU[2][3][0] = "我要提现";
		MENU[2][3][1] = "mb_editsettle.html";
		MENU[2][4][0] = "提现历史";
		MENU[2][4][1] = "mb_listsettle.html";
		MENU[2][5][0] = "伪冒罚款记录";
		MENU[2][5][1] = "mb_listpenalty.html";
		MENU[2][6][0] = "预存转存列表";
		MENU[2][6][1] = "bm_listdeposit.html";

		MENU[3][0][0] = "统计报表";
		MENU[3][0][1] = "nothing";
		MENU[3][1][0] = "日报";
		MENU[3][1][1] = "form_day.html";
		MENU[3][2][0] = "月报";
		MENU[3][2][1] = "form_month.html";
		MENU[3][3][0] = "网站统计";
		MENU[3][3][1] = "form_website.html";

		MENU[4][0][0] = "商户工具";
		MENU[4][0][1] = "nothing";
		MENU[4][1][0] = "接口下载";
		MENU[4][1][1] = "tool_install.html";
		MENU[4][2][0] = "开发文档";
		MENU[4][2][1] = "tool_document.html";
		MENU[4][3][0] = "汇率查询";
		MENU[4][3][1] = "currency_list.html";
		MENU[4][4][0] = "物流编码查询";
		MENU[4][4][1] = "tool_logic.html";
		MENU[4][5][0] = "国家编码查询";
		MENU[4][5][1] = "tool_country.html";
		MENU[4][6][0] = "创建支付链接";
		MENU[4][6][1] = "link_edit.html";
	}

	public static String build(String menu) {
		Set<String> set = StringUtil.toSet(menu);
		JSONArray jsonList = new JSONArray();
		for (int i = 0; i < 10; i++) {
			JSONArray jsonItem = new JSONArray();
			for (int j = 0; j < 10; j++) {
				if (set.contains(i + "" + j)) {
					jsonItem.add(j, "1");
				} else {
					jsonItem.add(j, "0");
				}
			}
			jsonList.add(i, jsonItem);
		}
		return jsonList.toString().replaceAll("\"", "'");
	}

	public static String plain(String menu) {
		StringBuffer sb = new StringBuffer();
		sb.append("<nav id='menu'>");
		sb.append("<ul>");
		sb.append("<li><a href='global_core.html'>首页</a></li>");

		JSONArray array = JSONArray.fromObject(menu);
		for (int i = 0; i < 10; i++) {
			JSONArray item = array.getJSONArray(i);
			if (item.get(0).equals("1") && MENU[i][0][0] != null) {
				sb.append("<li ><span><a href='javascript:void(0)' >");
				sb.append(MENU[i][0][0]);
				sb.append("</a></span>");
				sb.append("<ul >");
				for (int j = 1; j < 10; j++) {
					if (item.get(j).equals("1") && MENU[i][j][0] != null) {
						sb.append("<li><a href='" + MENU[i][j][1] + "'>" + MENU[i][j][0] + "</a></li>");
					}
				}
				sb.append("</ul >");
				sb.append("</li >");
			}
		}
		
		sb.append("<li><a href='subject_logout.html'>登出</a></li>");
		sb.append("</ul>");
		sb.append("</nav>");
		return sb.toString();
	}

	public static void main(String[] args) {
		String men = "[['1','1','1','1','1','1','1','1','1','1'],['1','1','1','1','1','1','1','1','1','1'],['1','1','1','1','1','1','1','1','1','1'],['1','1','1','1','1','1','1','1','1','1'],['1','1','1','1','1','1','1','1','1','1'],['1','1','1','1','1','1','1','1','1','1'],['1','1','1','1','1','1','1','1','1','1'],['1','1','1','1','1','1','1','1','1','1'],['1','1','1','1','1','1','1','1','1','1'],['1','1','1','1','1','1','1','1','1','1']]";

		System.out.println(plain(men));

	}
}
